<?php
/**
 * Base_App
 *
 * LICENSE
 *
 * This source file is subject to the new CC-GNU LGPL
 * It is available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/LGPL/2.1/
 *
 * @category   Base_App
 * @copyright  Copyright (c) 2009 Alexander fanatique* Thomas (me@alexander-thomas.net)
 * @license    http://creativecommons.org/licenses/LGPL/2.1/
 */
class Base_App
{
	private $_front;
	private static $_instance = null;

	/**
	 * Singleton Getter
	 */
	public static function getInstance(){
		if (null === self::$_instance) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	/**
	 * Ititializes the Base_App
	 * @param string $applicationPath 
	 */
	public function init($applicationPath){
		$init = Base_App_Initialization::getInstance();
		$init->registerApplicationPath($applicationPath);
		$environment = $init->getEnvironment();
		$appConfig = $init->setupApplicationConfig($environment);
		$init->setupLogger();
		$init->setupDb();
		$init->setupAcl();
		$init->setupSession(); 
		$init->setupTranslation();
		$init->getBuildNumber();
		$this->_front = Zend_Controller_Front::getInstance();
		$init->setupFrontController($this->_front, $environment);

		$router = $this->_front->getRouter();
		$init->setupRoutes($router);
		$init->setupHelperPaths();

		if($environment != 'production') $this->_front->throwExceptions(true);
	}

	/**
	 * Can be overridden for own purposes. This method gets called right before the original run()
	 */
	protected function _run(){
	}

	/**
	 * Runs the dispatch method on the frontcontroller
	 */
	public function run(){
		$this->_run();
		$this->_front->dispatch();
	}
	
	/**
	 * Geter for the front controller object (needed for initialization)
	 * @return Zend_Controller_Front
	 */
	public function getFrontController(){
		return $this->_front;
	}
}
?>
